package heip.generator.main;

import heip.generator.entity.EntityClazz;
import heip.generator.entity.EntityTable;
import heip.generator.generer.ActionGenerator;
import heip.generator.generer.EntityGenerator;
import heip.generator.generer.JSPGenerator;
import heip.generator.generer.ServiceGenerator;



/**
 * 已不推荐使用，因为2层表都使用gird方式实现
 * 两层表的临时表方式 代码生成器
 * @author HSWHM
 */
@Deprecated
public class TwoTableGenerator  extends BaseAbstractCodeGenerator{

	private String moduleName = "";//模块
	
	public static void main(String[] args)throws Exception{
		TwoTableGenerator gg = new TwoTableGenerator();
		
		//1.生成实体,请修改相关方法的变量
		gg.generatorTable();
		
		//2 生成类和配置文件,请修改相关方法的变量
		//生成bs,action,jsp请保证实体已先生成并以导入Heip工程
		//gg.generatorClazzAndJSP();
		
		open();
	}
	
	public void generatorTable() throws Exception {
		//EntityTable sub = new EntityTable("tc_pick_after", "before_id");//参数为 表名：tc_pick_after,外键:before_id
		//EntityTable mainTable = new EntityTable("tc_pick_before",sub);	//参数为 表名：tc_pick_after,子表对象：sub
		
		//生成代码
		//gt(mainTable);//只需要传入主表对象就可以了
	}
	
	public void generatorClazzAndJSP()throws Exception{
		//EntityClazz subClazz = new EntityClazz(TcPickOutDtl.class, "挑选出库单明细","outId");//参数：子表类Class,中文名称，外键属性名
		//EntityClazz mainClazz = new EntityClazz(TcPickOut.class, "挑选出库单",subClazz);//参数为：类class，中文名称，子表EntityClazz对象
		
		//生成代码
		//gc(mainClazz);//只需要传入主表对象就可以了
	}
	
	
	///////////////////////////////////////////////////////////
	///////////////////////////////////////////////////////////
	private void gt(EntityTable table) throws Exception{
		EntityGenerator eg = new EntityGenerator(moduleName);
		eg.generatorPO(new EntityTable[]{table}, null);
		eg.generatorVO(new EntityTable[]{table}, false);
		
		for(EntityTable et : table.getSubEntitys()){
			eg.generatorPO(new EntityTable[]{et}, null);
			eg.generatorVO(new EntityTable[]{et}, true);
			if(et.hasSubTable()){
				for(EntityTable ett :et.getSubEntitys()){
					eg.generatorPO(new EntityTable[]{ett}, null);
					eg.generatorVO(new EntityTable[]{ett}, true);
				}
			}
		}
	}
	
	private void gc(EntityClazz clazz)throws Exception{
		ServiceGenerator sg = new ServiceGenerator(moduleName);
		ActionGenerator ag = new ActionGenerator(moduleName);
		JSPGenerator jg = new JSPGenerator(moduleName);
	
		sg.generatorCacheBS(clazz);
		ag.generateTem4Two(clazz);
		jg.generateJsp4Two(clazz);
	}
}
